// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PEX_P08 : AbstractMessage
    {
		/// Constructor
		public PEX_P08() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "PEX", TriggerEvent = "P08" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("EVN",2)]
  	    [HL7Field(HL7Version.v23, 2, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v231, 2, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v24, 2, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v25, 3, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v251, 3, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v26, 4, HL7Repeat.False, HL7Required.True,"EVN")]
  	    [HL7Field(HL7Version.v27, 4, HL7Repeat.False, HL7Required.True,"EVN")]
	    public EVN EVN {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PID",3)]
  	    [HL7Field(HL7Version.v23, 3, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v231, 3, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v24, 3, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v25, 4, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v251, 4, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v26, 5, HL7Repeat.False, HL7Required.True,"PID")]
  	    [HL7Field(HL7Version.v27, 5, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PD1",5)]
  	    [HL7Field(HL7Version.v23, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v231, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v24, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v25, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v251, 5, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v26, 6, HL7Repeat.False, HL7Required.False,"PD1")]
  	    [HL7Field(HL7Version.v27, 6, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NTE",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v231, 9, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v24, 9, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v25, 6, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v251, 6, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v26, 7, HL7Repeat.True, HL7Required.False,"NTE")]
  	    [HL7Field(HL7Version.v27, 8, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("VISIT",12)]
  	    [HL7Field(HL7Version.v23, 12, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P08")]
  	    [HL7Field(HL7Version.v231, 12, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P07")]
  	    [HL7Field(HL7Version.v24, 12, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P07")]
  	    [HL7Field(HL7Version.v25, 7, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P07")]
  	    [HL7Field(HL7Version.v251, 7, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P07")]
  	    [HL7Field(HL7Version.v26, 8, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P07")]
  	    [HL7Field(HL7Version.v27, 9, HL7Repeat.False, HL7Required.False,"VISIT_PEX_P07")]
	    public VISIT_PEX_P08 VISIT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("EXPERIENCE",18)]
  	    [HL7Field(HL7Version.v23, 18, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P08")]
  	    [HL7Field(HL7Version.v231, 18, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P07")]
  	    [HL7Field(HL7Version.v24, 18, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P07")]
  	    [HL7Field(HL7Version.v25, 11, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P07")]
  	    [HL7Field(HL7Version.v251, 11, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P07")]
  	    [HL7Field(HL7Version.v26, 12, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P07")]
  	    [HL7Field(HL7Version.v27, 14, HL7Repeat.True, HL7Required.True,"EXPERIENCE_PEX_P07")]
	    public EXPERIENCE_PEX_P08[] EXPERIENCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("SFT",2)]
  	    [HL7Field(HL7Version.v25, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v251, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v26, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v27, 2, HL7Repeat.True, HL7Required.False,"SFT")]
	    public SFT[] SFT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UAC",3)]
  	    [HL7Field(HL7Version.v26, 3, HL7Repeat.False, HL7Required.False,"UAC")]
  	    [HL7Field(HL7Version.v27, 3, HL7Repeat.False, HL7Required.False,"UAC")]
	    public UAC UAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PRT",7)]
  	    [HL7Field(HL7Version.v27, 7, HL7Repeat.True, HL7Required.False,"PRT")]
	    public PRT[] PRT {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v23 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		}
		if (HL7Version.v231 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		}
		if (HL7Version.v24 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		}
		if (HL7Version.v25 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v251 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v26 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		}
		if (HL7Version.v27 == options.Version) {
		 EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 VISIT = ProcessGroup<VISIT_PEX_P08>(availableData, options, "VISIT");
		 EXPERIENCE = ProcessGroupArray<EXPERIENCE_PEX_P08>(availableData, options, "EXPERIENCE");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		 PRT = PopSegmentParseAndCheckRequiredArray<PRT>(availableData, options, "PRT");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PEX_P08";
			}
        }

        static PEX_P08() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PEX_P08));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (EVN != null) {
				segmentData.Add(EVN.GetER7(options));
			}
			if (PID != null) {
				segmentData.Add(PID.GetER7(options));
			}
			if (PD1 != null) {
				segmentData.Add(PD1.GetER7(options));
			}
			if (NTE != null && NTE.Length > 0) {
				for (int i = 0; i < NTE.Length; i++) {
					segmentData.Add(NTE[i].GetER7(options));
				}
			}
			if (VISIT != null) {
				segmentData.Add(VISIT.GetER7(options));
			}
			if (EXPERIENCE != null && EXPERIENCE.Length > 0) {
				for (int i = 0; i < EXPERIENCE.Length; i++) {
					segmentData.Add(EXPERIENCE[i].GetER7(options));
				}
			}
			if (SFT != null && SFT.Length > 0) {
				for (int i = 0; i < SFT.Length; i++) {
					segmentData.Add(SFT[i].GetER7(options));
				}
			}
			if (UAC != null) {
				segmentData.Add(UAC.GetER7(options));
			}
			if (PRT != null && PRT.Length > 0) {
				for (int i = 0; i < PRT.Length; i++) {
					segmentData.Add(PRT[i].GetER7(options));
				}
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

